using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;

namespace Mystery.SharePoint.Features.QuotaAdmin
{
    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>

    [Guid("76135b29-9545-4252-9603-5059eaa9bd00")]
    public class QuotaAdminEventReceiver : SPFeatureReceiver
    {
        private const string DefaultQuotaTemplateKey = "DefaultQuotaTemplate";

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;

            string quotaName = properties.Feature.Properties.Read(DefaultQuotaTemplateKey, string.Empty);

            if (quotaName != string.Empty)
            {
                site.SetDefaultQuotaTemplate(quotaName);
                site.RootWeb.Properties.Update();
            }
        }
    }
}
